#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<string>

using namespace std;

void KiemTraSoChan()
{
	int n;
	cout<<"Kiem tra mot so la chan hay le.\nNhap vao tu ban phim mot so:";
	cin>>n;
	if (n%2 == 0)
	{
		cout<<"So " << n << " la so chan !" << endl;
		return;
	}
	cout <<"So " << n << " deo phai la so chan !" << endl;
}


void KiemTraKyTuLaSo()
{
	char c;
	cout<<"Kiem tra mot ky tu co phai la so hay khong.\nNhap vao tu ban phim mot ky tu:";
	cin>>c;
	int nc = (int) c;
	if (nc <= 57 && nc >= 48)
	{
		cout << "Ky tu " << c << " la mot so !" << endl;
		return;
	}
	cout << "Ky tu " << c << " deo phai la mot so !" << endl;
}

void KiemTraKyTuLaMauTu()
{
	char c;
	cout<<"Nhap vao mot ky tu de kiem tra xem co phai mau tu hay khong:";
	cin>>c;
	if (((int) c >= 97 && (int) c<=122) || ((int) c >= 65 && (int)c <= 90))
	{
		cout << "Ky tu " << c << " la mot mau tu !" << endl;
		return;
	}
	else
	{
		cout << "Ky tu " << c << " deo phai la mot mau tu !" << endl;
	}
}

void KiemTraLeDuongHoacChanAm()
{
	int n;
	cout << "Kiem tra xem mot so la le duong hoac chan am\nNhap vao tu ban phim mot so:"; cin>>n;
	if (n%2 != 0 && n>=0)
	{
		cout<<"N la so LE va DUONG !" <<endl;
		return;
	}
	if (n%2 == 0 && n<0)
	{
		cout<<"N la so CHAN va AM !" << endl;
		return;
	}

	cout <<"So ban vua nhap vao deo co y nghia gi o chuc nang nay ca =))";
}

void GiaTriTuyetDoi()
{
	int n;
	cout <<"Gia tri tuyet doi\nNhap vao tu ban phim mot so:"; cin>>n;
	if (n<0) n = n*-1;
	cout<<"Gia tri tuyet doi cua so vua nhap la:" << n; 
}

void DoDoDaiChuoi()
{
	string mystr;
	cout <<"Kiem tra do dai cua chuoi.\nNhap vao mot chuoi tu ban phim:" <<endl;
	fflush(stdin);
	getline(cin, mystr);
	//cin >> mystr;
	cout <<"Do dai cua chuoi vua nhap la " << mystr.length() << "Ky tu";
}

int main(void)
{
	cout <<"Bai tap cuoi chuong 2. \n\nNhap tu ban phim de chon chuc nang: \n\
		1. Kiem tra so chan hay le. \n\
		2. Kiem tra mot ky tu co phai la so hay khong. \n\
		3. Kiem tra mot ky tu co phai la mau tu hay khong\n\
		4. Kiem tra mot so xem co phai la LE DUONG hoac CHAN AM \n\
		5. Tinh gia tri tuyet doi cua mot so. \n\
		6. Tinh do dai cua chuoi\n\
		" << endl;
	int i;
	cin >> i;
	switch (i)
	{
	case 1:
		KiemTraSoChan();
		break;
	case 2:
		KiemTraKyTuLaSo();
		break;
	case 3:
		KiemTraKyTuLaMauTu();
		break;
	case 4:
		KiemTraLeDuongHoacChanAm();
		break;
	case 5:
		GiaTriTuyetDoi();
		break;
	case 6:
		DoDoDaiChuoi();
		break;
	default:
		cout << "Lua chon cua ban khong hop le !";
		break;
	}
	_getch();
}

